package com.jy.shenghuilogistics.service;

import org.springframework.stereotype.Service;
import com.jy.shenghuilogistics.bean.Employee;
import com.jy.shenghuilogistics.dao.EmployeeMapper;

import javax.annotation.Resource;
import java.util.List;

@Service("backEmpService")
public class EmployService {
    @Resource
    EmployeeMapper employeeMapper;

    /**
     * 修改员工
     * @param e
     * @return
     */
    public Integer updEmp(Employee e) {
        if(e.getTruckId()!= null && e.getTruckId() == 0) {
            e.setTruckId(null);
        }
        if(e.getEmpId() != null && e.getEmpId() != 0) {
            return employeeMapper.updEmp(e);
        }else {
            return employeeMapper.updEmpByTel(e);
        }
    }

    /**
     * 添加员工
     * @param e
     * @return
     */
    public Integer addEmp(Employee e) {
        Integer account =  employeeMapper.selMaxAccountBySite(e.getSiteId());
        if(account == null || account == 0) {
            account = e.getSiteId()*10000+1;
        }else {
            account +=1;
        }
        e.setEmpAccount(account);
        if(employeeMapper.insEmp(e) > 0) {
            return account;
        }
        return 0;
    }
    /**
     * 模糊查询员工
     * @param e
     * @return
     */
    public List<Employee> selEmp(Employee e) {
        return employeeMapper.selEmp(e);
    }

    public Employee getEmpByAccPwd(Integer account, String pwd) {
        return employeeMapper.selEmpByAccPwd(account,pwd);
    }

    public Employee getEmpById(Integer id) {
        return employeeMapper.selEmpById(id);
    }
}
